package com.jtpay.unionpay.product.service;

import android.app.IntentService;
import android.content.Intent;
import com.jtpay.unionpay.product.MainActivity;
import com.jtpay.unionpay.product.dbUtils.CustomDbUtils;
import com.jtpay.unionpay.product.model.ProductBean;
import com.jtpay.unionpay.product.utils.LogUtil;

import static com.jtpay.unionpay.product.utils.ActivityHelper.startUnionPayMainActivity;

public class RemoteDataService extends IntentService {
    private static final String TAG = "RemoteDataService";

    public RemoteDataService() {
        super(TAG);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        MainActivity.getInstance().log("service onCreate");
    }

    @Override
    protected void onHandleIntent(final Intent intent) {
        try {
            LogUtil.log("service onHandleIntent");
            for (int i = 0; i < 50; i++) {
                ProductBean productBean = new ProductBean(
                        "0.1", "123456", "0");
                productBean.setSerialNumber(String.valueOf(i));
                CustomDbUtils.getInstance().insert(productBean);
                LogUtil.log(productBean.toString());
            }
            startUnionPayMainActivity();
        } catch (Exception e) {
            e.printStackTrace();
            MainActivity.getInstance().log("service intent param error : " + e.getMessage());
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        MainActivity.getInstance().log("service onDestroy");
    }
}